﻿<UserControl x:Class="TestProjectFileFunctions.DataBlockViewControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:TestProjectFileFunctions"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:Step7V51="clr-namespace:DotNetSiemensPLCToolBoxLibrary.DataTypes.Blocks.Step7V5;assembly=DotNetSiemensPLCToolBoxLibrary"
             xmlns:Step7V11="clr-namespace:DotNetSiemensPLCToolBoxLibrary.DataTypes.Blocks;assembly=DotNetSiemensPLCToolBoxLibrary"
             xmlns:step7V11="clr-namespace:DotNetSiemensPLCToolBoxLibrary.DataTypes.Blocks.Step7V11;assembly=DotNetSiemensPLCToolBoxLibrary"
             d:DesignHeight="300"
             d:DesignWidth="500"
             mc:Ignorable="d">

    <UserControl.Resources>
        <Style TargetType="TreeViewItem">
            <Style.Resources>
                <!--  Resources omitted for clarity…  -->
            </Style.Resources>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="TreeViewItem">
                        <StackPanel Margin="0" Orientation="Vertical">
                            <!--  Presents the Content  -->
                            <Border Name="sel"
                                    Margin="0"
                                    Padding="0">
                                <ContentPresenter Name="PART_Header"
                                                  Margin="0"
                                                  ContentSource="Header" />
                            </Border>
                            <!--  Presents the Children  -->
                            <Border Margin="0" Padding="0">
                                <ItemsPresenter x:Name="ItemsHost" Margin="0" />
                            </Border>
                        </StackPanel>

                        <ControlTemplate.Triggers>
                            <!--
                                When the item is selected in the TreeView, use the
                                "selected" colors and give it a drop shadow.
                            -->
                            <Trigger Property="IsSelected" Value="true">
                                <Setter TargetName="sel" Property="Background" Value="Blue" />
                                <!--  Setters omitted for clarity...  -->
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>

            <!--  Make each TreeViewItem show it's children  in a StackPanel.  -->
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel  Margin="0"
                                    HorizontalAlignment="Left"
                                    IsItemsHost="True" />
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>

            <Setter Property="VirtualizingStackPanel.IsVirtualizing" Value="True" />                
        </Style>

        <local:TreeviewDepthWidthConverter x:Key="lengthConverter" Width="19" />
        <local:TreeviewDepthWidthConverter x:Key="length2Converter"
                                           Width="330"
                                           preWidth="19" />

    </UserControl.Resources>

    <Grid Margin="0" Background="White">
        <!--
            <StackPanel Height="20" Orientation="Horizontal" Margin="0">
            <Border Padding="2" BorderThickness="1,1,1,1" BorderBrush="Black">
            <TextBlock TextAlignment="Right" Text="Address" Margin="0" Width="45"/>
            </Border>
            <Border Padding="2" Width="330" BorderThickness="1,1,1,1" BorderBrush="Black">
            <TextBlock Text="Name" Margin="0"/>
            </Border>
            <Border Padding="2" BorderThickness="1,1,1,1" BorderBrush="Black" Width="80">
            <TextBlock Text="DataType" Margin="0"/>
            </Border>
            <Border Padding="2" BorderThickness="1,1,1,1" BorderBrush="Black" Width="300">
            <TextBlock Text="Value" Margin="0"/>
            </Border>
            </StackPanel>
        -->

        <TreeView VirtualizingStackPanel.IsVirtualizing="True" Name="MyTree"
                  Margin="0,30,0,0"
                  Padding="0">
            <TreeView.Resources>
                <HierarchicalDataTemplate DataType="{x:Type step7V11:TIADataRow}" ItemsSource="{Binding Children}">
                    <Grid Margin="0">
                        <StackPanel Margin="0" Orientation="Horizontal">
                            <Border BorderBrush="Black"
                                    BorderThickness="1,1,1,1"
                                    Padding="2">
                                <TextBlock Width="45"
                                           Margin="0"
                                           Text="{Binding BlockAddress}"
                                           TextAlignment="Right" />
                            </Border>
                            <Border Width="{Binding Converter={StaticResource lengthConverter}}" Margin="0" />
                            <Border Width="{Binding Converter={StaticResource length2Converter}}"
                                    BorderBrush="Black"
                                    BorderThickness="1,1,1,1"
                                    Padding="2">
                                <TextBlock Margin="0"
                                           Text="{Binding Name}"
                                           ToolTip="{Binding StructuredName}" />
                            </Border>
                            <Border Width="300"
                                    BorderBrush="Black"
                                    BorderThickness="1,1,1,1"
                                    Padding="2">
                                <TextBlock Margin="0"
                                           Text="{Binding SymbolicVisuAccessKey}"
                                           ToolTip="{Binding SymbolicVisuAccessKey}" />
                            </Border>
                            <Border Width="180"
                                    BorderBrush="Black"
                                    BorderThickness="1,1,1,1"
                                    Padding="2">
                                <TextBlock Margin="0"
                                           Text="{Binding DataTypeAsString}"
                                           ToolTip="{Binding DataTypeAsString}" />
                            </Border>
                            <Border Width="180"
                                    BorderBrush="Black"
                                    BorderThickness="1,1,1,1"
                                    Padding="2">
                                <TextBlock Margin="0"
                                           Text="{Binding StartValueAsString}"
                                           ToolTip="{Binding StartValueAsString}" />
                            </Border>
                            <Border Width="180"
                                    BorderBrush="Black"
                                    BorderThickness="1,1,1,1"
                                    Padding="2">
                                <TextBlock Margin="0"
                                           Text="{Binding ValueAsString}"
                                           ToolTip="{Binding ValueAsString}" />
                            </Border>
                            <Border Width="300"
                                    BorderBrush="Black"
                                    BorderThickness="1,1,1,1"
                                    Padding="2">
                                <TextBlock Margin="0"
                                           Text="{Binding Comment}"
                                           ToolTip="{Binding Comment}" />
                            </Border>
                            <Border Width="300"
                                    BorderBrush="Black"
                                    BorderThickness="1,1,1,1"
                                    Padding="2">
                                <TextBlock Margin="0" Text="{Binding Path=LibNoDaveValue.Value}" />
                            </Border>
                        </StackPanel>
                    </Grid>
                </HierarchicalDataTemplate>
                <HierarchicalDataTemplate DataType="{x:Type Step7V51:S7DataRow}" ItemsSource="{Binding Children}">
                    <Grid Margin="0">                        
                        <StackPanel Margin="0" Orientation="Horizontal">
                            <Border BorderBrush="Black"
                                    BorderThickness="1,1,1,1"
                                    Padding="2">
                                <TextBlock Width="45"
                                           Margin="0"
                                           Text="{Binding BlockAddress}"
                                           TextAlignment="Right" />
                            </Border>
                            <Border Width="{Binding Converter={StaticResource lengthConverter}}" Margin="0" />
                            <Border Width="{Binding Converter={StaticResource length2Converter}}"
                                    BorderBrush="Black"
                                    BorderThickness="1,1,1,1"
                                    Padding="2">
                                <TextBlock Margin="0"
                                           Text="{Binding Name}"
                                           ToolTip="{Binding StructuredName}" />
                            </Border>
                            <Border Width="180"
                                    BorderBrush="Black"
                                    BorderThickness="1,1,1,1"
                                    Padding="2">
                                <TextBlock Margin="0"
                                           Text="{Binding DataTypeAsString}"
                                           ToolTip="{Binding DataTypeAsString}" />
                            </Border>                            
                            <Border Width="180"
                                    BorderBrush="Black"
                                    BorderThickness="1,1,1,1"
                                    Padding="2">
                                <TextBlock Margin="0"
                                           Text="{Binding StartValueAsString}"
                                           ToolTip="{Binding StartValueAsString}" />
                            </Border>
                            <Border Width="180"
                                    BorderBrush="Black"
                                    BorderThickness="1,1,1,1"
                                    Padding="2">
                                <TextBlock Margin="0"
                                           Text="{Binding ValueAsString}"
                                           ToolTip="{Binding ValueAsString}" />
                            </Border>
                            <Border Width="300"
                                    BorderBrush="Black"
                                    BorderThickness="1,1,1,1"
                                    Padding="2">
                                <TextBlock Margin="0"
                                           Text="{Binding Comment}"
                                           ToolTip="{Binding Comment}" />
                            </Border>
                            <Border Width="300"
                                    BorderBrush="Black"
                                    BorderThickness="1,1,1,1"
                                    Padding="2">
                                <TextBlock Margin="0" Text="{Binding Path=LibNoDaveValue.Value}" />
                            </Border>
                        </StackPanel>
                    </Grid>
                </HierarchicalDataTemplate>
            </TreeView.Resources>

            <TreeView.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel />
                </ItemsPanelTemplate>
            </TreeView.ItemsPanel>
        </TreeView>
        <RadioButton x:Name="chkProjectString" Content="Structure from Project String" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" IsChecked="True" Checked="chkProjectString_Checked"/>
        <RadioButton x:Name="chkMC7Code" Content="Structure from MC7 Code" HorizontalAlignment="Left" Margin="262,5,0,0" VerticalAlignment="Top" Checked="chkMC7Code_Checked"/>


    </Grid>
</UserControl>
